package com.stox.ui.javafx.charting.event.listener;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.charting.widget.PrimaryChart;

@SuppressWarnings("rawtypes")
@Component("rangeSliderValueChangeListener")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class RangeSliderValueChangeListener implements ChangeListener<Number> {

	private final PrimaryChart primaryChart;
	
	public RangeSliderValueChangeListener(PrimaryChart primaryChart) {
		this.primaryChart = primaryChart;
	}
	
	@Override
	public void changed(ObservableValue<? extends Number> paramObservableValue,Number paramT1, Number paramT2) {
		primaryChart.getChartingView().setZoom(primaryChart.getRangeSlider().getLowValue(), primaryChart.getRangeSlider().getHighValue());
		if(!primaryChart.getChartingView().isLoading()){
			primaryChart.getChartingView().update();
		}
	}

}
